<form action="index.php?app=weixin&ctl=admin_message_image&act=save_item_imageMessage" id='addimagereply-edit-form' method="POST">
  <{input type="hidden" name='id' value=$data.id}>
	<div class="tableform">
		<div class="division">
      <table width="100%" cellspacing="0" cellpadding="0">
        <tbody>
          <tr>
            <th><em class="red">*</em><label for="title"><{t}>图文名称:<{/t}></label></th>
            <td><{input type="text" name="name" value=$data.name id="title" size=28  vtype="required" class="x-input " autocomplete="off"}></td>
          </tr>
          <{if $data.parent_id == '0'}>
          <tr>
            <th>
            <em class="red">*</em><label for="is_check_bind"><{t}>是否需要检查免登绑定：<{/t}></label>
            </th>
            <td>
            <input type="radio" name="is_check_bind" value='true' <{if $data.is_check_bind == 'true'}>checked<{/if}>> <{t}>是<{/t}>
            <input type="radio" name="is_check_bind" value='false'<{if $data.is_check_bind != 'true'}>checked<{/if}>> <{t}>否<{/t}> 
            </td>
          </tr>
          <{/if}>
          <tr>
            <th><label for="title"><{t}>上级菜单:<{/t}></label></th>
            <td>
              <{input type='select' noselect=true name='parent_id' value=$data.parent_id required='true' vtype='required' caution=$__weixin='请选择上级菜单'|t:'weixin' rows=$selectmaps valueColumn="id" labelColumn="name"}>
            </td>
          </tr>
          <tr> 
            <th><label for="title"><{t}>排序:<{/t}></label></th>
            <td>
              <{input type='text' name='ordernum' size='3' vtype='required&&number' caution=$__weixin='请填写排序值'|t:'weixin' value=$data.ordernum|default:'0' }>
              <span class="notice-inline"><{t}>数字越小越靠前<{/t}> </span>
            </td>
          </tr>
          <tr>
            <th><em class="red">*</em><label for="title"><{t}>标题:<{/t}></label></th>
            <td><{input type="text" name="title" value=$data.title id="title" size=28 required="1" vtype="required" class="x-input " autocomplete="off"}></td>
          </tr>
          <tr>
            <{if $data.parent_id == '0'}>
            <th><em class="red"></em><label for="picurl"><{t}>封面图片:<{/t}></label></th>
            <td>
              <{input type="image" name="picurl" id="picurl" value=$data.picurl class="x-input"  vtype="required" autocomplete="off" width=135 height=75}>
              <span class="notice"><{t}>图片链接，支持JPG、PNG格式，较好的效果为360*200<{/t}> </span>
            </td>
            <{else}>
            <th><em class="red"></em><label for="picurl"><{t}>图文图片:<{/t}></label></th>
            <td>
              <{input type="image" name="picurl" id="picurl" value=$data.picurl class="x-input"  vtype="required" autocomplete="off" width=75 height=75}>
              <span class="notice"><{t}>图片链接，支持JPG、PNG格式，较好的效果为200*200<{/t}> </span>
            </td>
            <{/if}>
          </tr>
          <tr>
            <{if $data.parent_id == '0'}>
            <th><em class="red"></em><label for="url"><{t}>点击封面链接至:<{/t}></label></th>
            <{else}>
            <th><em class="red"></em><label for="url"><{t}>点击图片链接至:<{/t}></label></th>
            <{/if}>
            <td>
              <{input type="text" name="url" id="_msg_url" value=$data.url vtype='url' size=68 placeholder='http://' class="x-input " autocomplete="off"}>
              <table  class="gridlist">
                <tr class="module_link">
                  <th><{t}>商品详细页:<{/t}></th>
                  <td>
                    <{input type="object" name='product_id' breakpoint=0 cols='name' textcol="name" object="products@b2c" select='radio' callback="_callback_product"}>
                  </td>
                </tr>
                <tr class="module_link">
                  <th><{t}>商品列表页:<{/t}></th>
                  <td>
                    <{input type="object" breakpoint=0 name='cat_id' cols='cat_name' textcol="cat_name" object="goods_cat@b2c" select='radio' callback="_callback_gallery"}>
                  </td>
                </tr>
                <tr class="module_link">
                  <th><{t}>文章列表页:<{/t}></th>
                  <td>
                    <{input type='select' name='node_id' value=0 rows=$article_nodes valueColumn="node_id" labelColumn="node_name" onchange="_callback_articlelist(this.value)"}>
                  </td>
                </tr>
                <tr class="module_link">
                  <th><{t}>文章页:<{/t}></th>
                  <td>
                    <{input type="object" breakpoint=0 filter="platform=wap" name='article_id' cols='title' textcol="title" object="article_indexs@content" select='radio' callback="_callback_article"}>
                  </td>
                </tr>
                <tr class="module_link">
                  <th><{t}>需授权页:<{/t}></th>
                  <td>
                    <{input type='select'  name='auth_url' rows=$auth_module valueColumn="url" labelColumn="label" onchange="$('_msg_url').value=this.value;"}>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
  <div class="table-action">
    <table width="100%" cellspacing="0" cellpadding="0">
      <tbody>
        <tr>
          <td>
            <{button class="btn-primary" id="addimagereply-edit-form-submit" type="submit" label=$___weixin="保存"|t:'weixin'}>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</form>
<script>
  (function(){
    var _form = $('addimagereply-edit-form');
    var btn =$('addimagereply-edit-form-submit');
    var finder = finderGroup['<{$env.get._finder.finder_id}>'];

    _form.store('target',{
      onSuccess:function(response){
        var hash_res_obj = JSON.decode(response);

        if (hash_res_obj.success != undefined && hash_res_obj.success != "")
    {
      try{
        var _dialogIns = btn.getParent('.dialog').retrieve('instance');
      }catch(e){}

      if(_dialogIns)
    {
      _dialogIns.close();
      //window.finderGroup['<{$env.get._finder.finder_id}>'].refresh();
    }
    }

      }
    });
    btn.addEvent('click',function(){
      _form.fireEvent('submit',{stop:$empty});
    });

  })();

function _callback_product(rs){
  var _data = JSON.decode(rs);
  if(_data.id){
    new Request.JSON({
      url:'index.php?app=weixin&ctl=admin_menu&act=get_product_url',
      method:'post',
      data:'product_id='+_data.id,
      onComplete:function(ret){
        $('_msg_url').value = ret;
      }
    }).send();
  }
}

function _callback_gallery(rs){
  var _data = JSON.decode(rs);
  if(_data.id){
    new Request.JSON({
      url:'index.php?app=weixin&ctl=admin_menu&act=get_gallery_url',
      method:'post',
      data:'cat_id='+_data.id,
      onComplete:function(ret){
        $('_msg_url').value = ret;
      }
    }).send();
  }
}

function _callback_articlelist(_node_id){
  if(_node_id){
    new Request.JSON({
      url:'index.php?app=weixin&ctl=admin_menu&act=get_articlelist_url',
      method:'post',
      data:'node_id='+_node_id,
      onComplete:function(ret){
        console.log(ret);
        $('_msg_url').value = ret;
      }
    }).send();
  }
}

function _callback_article(rs){
  var _data = JSON.decode(rs);
  if(_data.id){
    new Request.JSON({
      url:'index.php?app=weixin&ctl=admin_menu&act=get_article_url',
      method:'post',
      data:'article_id='+_data.id,
      onComplete:function(ret){
        $('_msg_url').value = ret;
      }
    }).send();
  }
}

(function(){
  $$(".module_link").addEvent('click', function(e) {
    this.getElement('th').setStyle('color','red');
    this.getSiblings('.module_link').getElement('th').setStyle('color','');
  })
})();

</script>
